package com.glink.gateway.common;

import org.bouncycastle.crypto.digests.SM3Digest;
import org.bouncycastle.util.encoders.Hex;

/**
 * 国密Sm3
 *
 * @author rcl026@163.com
 * @date 2023/2/6
 * @since
 */
public class Sm3EncryptionUtil {

    public static String hash1(String data) {
        return Hex.toHexString(hash2(data));
    }

    private static byte[] hash2(String data) {
        SM3Digest sm3Digest = new SM3Digest();
        byte[] srcData = data.getBytes();
        sm3Digest.update(srcData, 0, srcData.length);
        byte[] hash = new byte[sm3Digest.getDigestSize()];
        sm3Digest.doFinal(hash, 0);
        return hash;
    }
}
